package com.ews.onlineexchange.controller;

import java.util.ArrayList;
import java.util.List;

import javax.enterprise.inject.Model;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;

import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.model.ServiceSupplier;
import com.ews.onlineexchange.service.EntityQuery;

@Model
public class ServiceSupplierProfessionRatingList extends EntityQuery<ServiceSupplier> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Inject
	EntityManager entityManager;
	public ServiceSupplierProfessionRatingList() {
		setOrder("auditted DESC,createDate desc");
		setMaxResults(MAX_RESULTS_NORMAL);
	}

	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<ServiceSupplier> entity) {
		List<Predicate> restrictions = new ArrayList<Predicate>();
		restrictions.add(cb.isTrue(entity.<Boolean>get("auditted")));
//		restrictions.add(cb.isTrue(entity.<Boolean>get("valid")));
		restrictions.add(cb.equal(entity.get("delFlag"),DataEntity.DEL_FLAG_NORMAL));
		String supplierName = (String)getParameterValues().get("supplierName");
		if (!StringUtils.isBlank(supplierName))
			restrictions.add(cb.like(entity.get("cnname"), getStringRestriction(supplierName)));
	
		return restrictions;
	}

	@Override
	protected void fetch(Root<ServiceSupplier> entity) {
		
	}


}
